package com.bitcat.firstapp.demo.component

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.widget.doOnTextChanged
import com.bitcat.firstapp.R
import com.bitcat.firstapp.databinding.ActivityTextInputDemoBinding

class TextInputDemoActivity : AppCompatActivity() {

    private lateinit var binding: ActivityTextInputDemoBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityTextInputDemoBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(40, systemBars.top, 40, systemBars.bottom)
            insets
        }

        binding.phoneEdit.doOnTextChanged { text, start, before, count ->
            if (text?.length != 11) {
                binding.phoneInput.error = "请输入11位的手机号"
            } else {
                binding.phoneInput.error = null
            }
        }
    }
}